﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled.
// If you have enabled NRTs for your project, then un-comment the following line:
// #nullable disable

namespace WebApiTest.Models
{
    public partial class officeContext : DbContext
    {
        public officeContext()
        {
        }

        public officeContext(DbContextOptions<officeContext> options)
            : base(options)
        {
        }

        public virtual DbSet<BasicUser> BasicUser { get; set; }
        public virtual DbSet<Collect> Collect { get; set; }
        public virtual DbSet<Dept> Dept { get; set; }
        public virtual DbSet<OfficeObject> OfficeObject { get; set; }
        public virtual DbSet<Person> Person { get; set; }
        public virtual DbSet<SystemMenu> SystemMenu { get; set; }
        public virtual DbSet<SystemPermission> SystemPermission { get; set; }
        public virtual DbSet<SystemRole> SystemRole { get; set; }
        public virtual DbSet<Tte> Tte { get; set; }
        public virtual DbSet<Type> Type { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
                optionsBuilder.UseMySql("server=116.62.129.112;uid=root;pwd=Hbh@20010809;port=3306;database=office;allow user variables=True", x => x.ServerVersion("8.0.28-mysql"));
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<BasicUser>(entity =>
            {
                entity.HasKey(e => e.UserId)
                    .HasName("PRIMARY");

                entity.ToTable("basic_user");

                entity.HasComment("用户信息表，用于用户账号的登录和信息管理。");

                entity.Property(e => e.UserId)
                    .HasColumnName("user_id")
                    .HasComment("用户ID，主键");

                entity.Property(e => e.GmtCreate)
                    .HasColumnName("gmt_create")
                    .HasColumnType("datetime")
                    .HasComment("创建时间");

                entity.Property(e => e.LoginName)
                    .HasColumnName("login_name")
                    .HasColumnType("varchar(50)")
                    .HasComment("登录账号")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_general_ci");

                entity.Property(e => e.LoginPwd)
                    .HasColumnName("login_pwd")
                    .HasColumnType("varchar(64)")
                    .HasComment("登录密码")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_general_ci");

                entity.Property(e => e.RoleId)
                    .HasColumnName("role_id")
                    .HasComment("用户角色ID，外键");

                entity.Property(e => e.UserImage)
                    .HasColumnName("user_image")
                    .HasColumnType("varchar(500)")
                    .HasComment("用户头像")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_general_ci");

                entity.Property(e => e.UserInfo)
                    .HasColumnName("user_info")
                    .HasColumnType("varchar(100)")
                    .HasComment("备注信息")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_general_ci");

                entity.Property(e => e.UserName)
                    .HasColumnName("user_name")
                    .HasColumnType("varchar(100)")
                    .HasComment("用户姓名")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_general_ci");
            });

            modelBuilder.Entity<Collect>(entity =>
            {
                entity.ToTable("collect");

                entity.Property(e => e.CollectId).HasColumnName("collect_id");

                entity.Property(e => e.CollectNum).HasColumnName("collect_num");

                entity.Property(e => e.CollectTime)
                    .HasColumnName("collect_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.ObjectId).HasColumnName("object_id");

                entity.Property(e => e.PersonId).HasColumnName("person_id");
            });

            modelBuilder.Entity<Dept>(entity =>
            {
                entity.ToTable("dept");

                entity.Property(e => e.DeptId).HasColumnName("dept_id");

                entity.Property(e => e.DeptName)
                    .HasColumnName("dept_name")
                    .HasColumnType("varchar(255)")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_0900_ai_ci");
            });

            modelBuilder.Entity<OfficeObject>(entity =>
            {
                entity.HasKey(e => e.ObjectId)
                    .HasName("PRIMARY");

                entity.ToTable("office_object");

                entity.Property(e => e.ObjectId).HasColumnName("object_id");

                entity.Property(e => e.GmtCreate)
                    .HasColumnName("gmt_create")
                    .HasColumnType("datetime");

                entity.Property(e => e.GmtUpdate)
                    .HasColumnName("gmt_update")
                    .HasColumnType("datetime");

                entity.Property(e => e.IsDelete).HasColumnName("is_delete");

                entity.Property(e => e.Number).HasColumnName("number");

                entity.Property(e => e.ObjectName)
                    .HasColumnName("object_name")
                    .HasColumnType("varchar(255)")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_0900_ai_ci");

                entity.Property(e => e.TypeId).HasColumnName("type_id");
            });

            modelBuilder.Entity<Person>(entity =>
            {
                entity.ToTable("person");

                entity.Property(e => e.PersonId).HasColumnName("person_id");

                entity.Property(e => e.DeptId).HasColumnName("dept_id");

                entity.Property(e => e.Name)
                    .HasColumnName("name")
                    .HasColumnType("varchar(255)")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_0900_ai_ci");

                entity.Property(e => e.Phone)
                    .HasColumnName("phone")
                    .HasColumnType("varchar(255)")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_0900_ai_ci");
            });

            modelBuilder.Entity<SystemMenu>(entity =>
            {
                entity.HasKey(e => e.MenuId)
                    .HasName("PRIMARY");

                entity.ToTable("system_menu");

                entity.Property(e => e.MenuId)
                    .HasColumnName("menu_id")
                    .HasComment("菜单标识，主键")
                    .ValueGeneratedNever();

                entity.Property(e => e.MenuCode)
                    .IsRequired()
                    .HasColumnName("menu_code")
                    .HasColumnType("varchar(30)")
                    .HasComment("菜单编码")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_general_ci");

                entity.Property(e => e.MenuFather)
                    .HasColumnName("menu_father")
                    .HasComment("父菜单");

                entity.Property(e => e.MenuName)
                    .IsRequired()
                    .HasColumnName("menu_name")
                    .HasColumnType("varchar(50)")
                    .HasComment("菜单名称")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_general_ci");

                entity.Property(e => e.MenuStatus)
                    .HasColumnName("menu_status")
                    .HasComment("菜单状态（1--禁用 0--正常）");

                entity.Property(e => e.MenuType)
                    .HasColumnName("menu_type")
                    .HasDefaultValueSql("'2'")
                    .HasComment("菜单类型（1--一级 2--二级）");
            });

            modelBuilder.Entity<SystemPermission>(entity =>
            {
                entity.HasKey(e => e.PermissionId)
                    .HasName("PRIMARY");

                entity.ToTable("system_permission");

                entity.Property(e => e.PermissionId)
                    .HasColumnName("permission_id")
                    .HasComment("权限ID，主键");

                entity.Property(e => e.GmtCreate)
                    .HasColumnName("gmt_create")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("CURRENT_TIMESTAMP")
                    .HasComment("创建时间")
                    .ValueGeneratedOnAddOrUpdate();

                entity.Property(e => e.MenuId)
                    .HasColumnName("menu_id")
                    .HasComment("菜单ID");

                entity.Property(e => e.RoleId)
                    .HasColumnName("role_id")
                    .HasComment("角色ID");
            });

            modelBuilder.Entity<SystemRole>(entity =>
            {
                entity.HasKey(e => e.RoleId)
                    .HasName("PRIMARY");

                entity.ToTable("system_role");

                entity.Property(e => e.RoleId)
                    .HasColumnName("role_id")
                    .HasComment("角色ID，主键");

                entity.Property(e => e.GmtCreate)
                    .HasColumnName("gmt_create")
                    .HasColumnType("datetime")
                    .HasComment("创建时间");

                entity.Property(e => e.RoleInfo)
                    .HasColumnName("role_info")
                    .HasColumnType("varchar(100)")
                    .HasComment("备注信息")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_general_ci");

                entity.Property(e => e.RoleName)
                    .HasColumnName("role_name")
                    .HasColumnType("varchar(20)")
                    .HasComment("角色名称")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_general_ci");
            });

            modelBuilder.Entity<Tte>(entity =>
            {
                entity.HasNoKey();

                entity.ToView("tte");

                entity.HasComment("View 'office.tte' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them");
            });

            modelBuilder.Entity<Type>(entity =>
            {
                entity.ToTable("type");

                entity.Property(e => e.TypeId).HasColumnName("type_id");

                entity.Property(e => e.TypeName)
                    .HasColumnName("type_name")
                    .HasColumnType("varchar(255)")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_0900_ai_ci");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
